package concurrency.tij;

class Car {
	private boolean waxed = false;

	public synchronized void waxed() {
		waxed = true;
		notifyAll();
	}

	public synchronized void buffed() {
		waxed = false;
		notifyAll();
	}

	public synchronized void waitForWaxing() throws InterruptedException {
		if (waxed == false)
			wait();
	}

	public synchronized void waitForBuffing() throws InterruptedException {
		if (waxed == true)
			wait();
	}
}

class WaxOn implements Runnable {
	private Car car;

	public WaxOn(Car car) {
		this.car = car;
	}

	public void run() {
		while (!Thread.interrupted()) {
        	car.waxed();
        }
	}
}

class WaxOff implements Runnable {
	private Car car;

	public WaxOff(Car car) {
		this.car = car;
	}

	public void run() {
		try {
			while (!Thread.interrupted()) {
				car.waitForWaxing();

			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}

public class WaxOMatic {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
